package recursion;

/**
 * @ClassName: leetcode HanoiDemo @Description: 学习使用 @Author: 逸伦 @Date: 2022/5/22 17:25 @Version:
 * 1.0
 */
public class HanoiDemo {

    private static final String msg = "将编号为%s的盘子,从%s移动到%s";

    public static void main(String[] args) {

        moveHanoi(3, "A", "B", "C");
        //    System.out.println(String.format(msg, 3, "A", "C"));
    }

    static void moveHanoi(int n, String a, String b, String c) {

        if (n == 1) {
            System.out.println(String.format(msg, n, a, c));
            return;
        }
        //      将n-1个盘子从A移动到B
        moveHanoi(n - 1, a, c, b);
        //      将编号为n的盘子从A移动到C
        System.out.println(String.format(msg, n, a, b));
        //      将n-1个盘子从B移动到C
        moveHanoi(n - 1, b, a, c);
    }
}
